﻿#region
/*******************************************************************************
** File Name:		    TableTypeService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class TableTypeService : ITableTypeService
    {
		 ITableType tableType = new TableTypeRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByTableTypeID (TableTypeModel model)
		{
			ETableType entity = ConvertModelToEntity(model);

            tableType.UpdateByTableTypeID(entity);

		}

		public void DeleteByTableTypeID (System.Int64 tableTypeID)
		{
		
            tableType.DeleteByTableTypeID(tableTypeID);

		}
		 
        public TableTypeModel GetByTableTypeID (System.Int64 tableTypeID)
        {
        
			ETableType entity = tableType.GetByTableTypeID(tableTypeID);
			
            TableTypeModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<TableTypeModel> GetAll ()
		{
			IList<ETableType> entity = tableType.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<TableTypeModel> list = new List<TableTypeModel>();

            foreach (var item in entity)
            {
                TableTypeModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private TableTypeModel ConvertEntityToModel(ETableType entity)
		{
			if (entity == null)
            {
                return null;
            }
			TableTypeModel model = new TableTypeModel();
                        model.TableTypeID = entity.TableTypeID;
                        model.Code = entity.Code;
                        model.Name = entity.Name;
                        model.Remark = entity.Remark;
                        model.ServiceRate = entity.ServiceRate;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private ETableType ConvertModelToEntity(TableTypeModel model)
		{
			if (model == null)
            {
                return null;
            }
			ETableType entity = new ETableType();
                        entity.TableTypeID = model.TableTypeID;
                        entity.Code = model.Code;
                        entity.Name = model.Name;
                        entity.Remark = model.Remark;
                        entity.ServiceRate = model.ServiceRate;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}